package 剑指offer.Month7_07.day16;

import java.util.ArrayList;

public class 和为S的两个数字 {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum){
        int i = 0;
        int j = array.length - 1;
        while(i < j){
            int num = array[i] + array[j];
            if(num > sum){
                j--;
            }else if(num < sum){
                i++;
            }else{
                ArrayList<Integer> list = new ArrayList<>();
                list.add(array[i]);
                list.add(array[j]);
                return list;
            }
        }
        return new ArrayList<>();
    }
}
